// ** Third Party Components
import axios from 'axios'
import { FileText } from 'react-feather'
import { UncontrolledTooltip } from 'reactstrap'

export let data

// ** Get initial Data
data = [
  {
    id: '1',
    task: '测试任务01',
    taskCom: '测试分组01',
    status: {
      value: 0,
      label: '暂停',
    },
    interval: '1200ms',
    apiUrl: 'http://127.0.0.1:3000/testApi/test?parameter=test',
    lastTime: '2023-09-13 14:02:29',
    describe: '测试api',
    type: 'API',
  },
  {
    id: '2',
    task: '测试任务02',
    taskCom: '测试分组02',
    status: {
      value: 0,
      label: '暂停',
    },
    interval: '1200ms',
    apiUrl: '-',
    lastTime: '2023-09-13 14:02:29',
    describe: '测试api',
    type: 'DLL',
  },
]

const statusEnum = {
  0: '#ea5455',
  1: '#56affd',
}
// ** Table Common Column
export const columns = (handleEdit, handleDelete) => [
  {
    name: '序号',
    width: '70px',
    cell: (row, a) => a + 1,
  },
  {
    name: '任务',
    minWidth: '150px',
    selector: (row) => row.task,
  },
  {
    name: '任务分组',
    minWidth: '150px',
    selector: (row) => row.grouping,
  },
  {
    name: '间隔时间',
    minWidth: '150px',
    selector: (row) => row.interval,
  },
  {
    name: 'ApiUrl',
    minWidth: '150px',
    selector: (row) => row.apiUrl,
  },
  {
    name: '运行状态',
    minWidth: '150px',
    cell: (row) => (
      <span
        style={{
          color: statusEnum[row.status.value],
          border: `1px solid ${statusEnum[row.status.value]}`,
          borderRadius: '4px',
          padding: '1px 4px',
        }}
      >
        {row.status.label}
      </span>
    ),
  },
  {
    name: '最近一次运行时间',
    minWidth: '150px',
    selector: (row) => new Date(row.lastTime).toLocaleDateString(),
  },
  {
    name: '任务描述',
    minWidth: '150px',
    selector: (row) => row.describe,
  },
  {
    name: '任务类型',
    minWidth: '150px',
    selector: (row) => row.apiType,
  },
  {
    name: '操作',
    width: '200px',
    selector: (row) => (
      <div
        className="column-action d-flex align-items-center"
        style={{ color: '#7367f0' }}
      >
        <div
          onClick={() => {
            handleEdit(row._id)
          }}
          className="ms-50 cursor-pointer"
        >
          执行记录
        </div>
        <div
          onClick={() => {
            handleDelete(row._id)
          }}
          className="ms-50 cursor-pointer"
        >
          删除
        </div>
      </div>
    ),
  },
]
